//--------------------------------------------------------------
//
// Qizhi Zhang 
// ezhung@gmail.com
// http://www.moorwind.com
//
//--------------------------------------------------------------
package reader.controller
{
	import mx.controls.Alert;
	import mx.events.CloseEvent;
	
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.command.SimpleCommand;
	
	import reader.ApplicationFacade;
	import reader.core.ReaderResource;
	import reader.core.UserConfirmCommandConfig;
	import reader.model.vo.TitleWindowVO;

	public class RemoveLabelCommand extends SimpleCommand implements ICommand
	{
		//////////////////////////////////////////////////////////////////////////////
		//private variables
		private var titleWindow:TitleWindowVO;
		private var isArray:Boolean;
		private var resource:XML = ReaderResource.instance.resource;
		
		//////////////////////////////////////////////////////////////////////////////
		//methods
		
		override public function execute(notification:INotification):void
		{
			titleWindow = notification.getBody() as TitleWindowVO;
			var alertMessage:String;
			if(titleWindow.blogLabel)
			{
				if(titleWindow.blogLabel.length == 1)
				{
					alertMessage = resource.settingPanelManageSubRemoveLabelButtonAlert + " " + titleWindow.blogLabel[0].name + " ?"
				}
				else
				{
					alertMessage = resource.settingPanelManageSubRemoveAllLabelButtonAlert;
					isArray = true;
				}
			}
			var cfm:UserConfirmCommandConfig = new UserConfirmCommandConfig(resource.settingPanelManageSubDelLabel, alertMessage, titleWindow.parent, onRemoveLabel_handler);
			facade.sendNotification(ApplicationFacade.REQUEST_USERCONFIRM, cfm);
		}
		
		private function onRemoveLabel_handler():void
		{
			if(isArray)
			{
				titleWindow.dataProxy.removeLabels(titleWindow.blogLabel);
			}
			else
			{
				titleWindow.dataProxy.removeLabel(titleWindow.blogLabel[0]);
				sendNotification(ApplicationFacade.REMOVED_LABEL, titleWindow.blogLabel[0]);
			}
		}
		
	}
}